package com.stu_ques.demo.service.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.stu_ques.demo.dao.IDynastyDao;
import com.stu_ques.demo.dao.IKingDao;
import com.stu_ques.demo.pojo.Dynasty;
import com.stu_ques.demo.pojo.King;
import com.stu_ques.demo.service.IDemoService;

public class DemoServiceImpl implements IDemoService
{
	
	/*Service调用朝代Dao*/
	private IDynastyDao dynastyDao;
	/*service中调用皇上Dao*/
	private IKingDao kingDao;
	@Override
	public int saveOneDemoService(Dynasty dynasty)
	{
		return this.dynastyDao.saveOneDao(dynasty);
	}

	@Override
	public void updateOneDemoService(Dynasty dynasty)
	{
		this.dynastyDao.updateOneDao(dynasty);
	}

	@Override
	public void deleteOneDemoService(Dynasty dynasty)
	{
		this.dynastyDao.deleteOneDao(dynasty);
	}

	@Override
	public Dynasty selectDemoService(Map<String , Object> condMap)
	{
		return this.dynastyDao.selectOneDao(condMap);
	}

	@Override
	public List<Dynasty> selectListDemoService()
	{
		return this.dynastyDao.selectListDao();
	}

	@Override
	public String printTitleDynastyService()
	{
		String sre ="id\t名字\t首都\t年龄\t开国时间\t\t\t创建时间\t\t\t更新时间" ; 
		return sre ;
	}
	/**
	 * service 添加一个皇上的实现方法
	 * */
	public int saveOneDemoKingService(King king)
	{
		return this.kingDao.saveOneDao(king);
	}
	/**
	 * service 更新一个皇上de实现方法
	 * */
	@Override
	public void updateOneDemoKingService(King king)
	{
		this.kingDao.updateOneDao(king);
	}
	/**
	 * service 删除一个皇上de实现方法
	 * */
	@Override
	public void deleteOneDemoKingService(King king)
	{
		this.kingDao.deleteOneDao(king);
	}
	/**
	 * service 查询一个皇上de实现方法
	 * */
	@Override
	public King selectDemoKingService(Map<String, Object> condMap)
	{
		return this.kingDao.selectOneDao(condMap);
	}
	/**
	 * service  查询所有皇上de实现方法
	 */
	@Override
	public List<King> selectListDemoKingService()
	{
		/*	参照查询一条朝代的方法	*/
		List<King> kingList = this.kingDao.selectListDao();
		
		Map<String,Object> condMap = new HashMap<String, Object>();
		/*循环List*/
		for (Iterator iterator = kingList.iterator(); iterator.hasNext();)
		{
			King king = (King) iterator.next();
			/* 根据id 查询皇上表的id*/
			condMap.clear();
			
			condMap.put("id", king.getDynastyId());
			
			Dynasty dunasty = this.selectDemoService(condMap);
			/*将结果给用户表*/
			king.setDynasty(dunasty);
		}
		return kingList;
	}
	/**
	 * service 皇上的打印标题
	 */
	@Override
	public String printTitleKingService()
	{
		//皇上 属性:id,朝代Id,名字,年龄,身高,庙号,年号,创建时间,更新时间 
		String sre ="id\t朝代\t名字\t年龄\t身高\t庙号\t年号\t创建时间\t\t\t更新时间" ; 
		return sre ;
	}

	public void setDynastyDao(IDynastyDao dynastyDao)
	{
		this.dynastyDao = dynastyDao;
	}

	public void setKingDao(IKingDao kingDao)
	{
		this.kingDao = kingDao;
	}

}
